<!--
 * @Description: In User Settings Edit
 * @Author: your name
 * @Date: 2019-07-30 20:02:30
 * @LastEditTime: 2020-03-19 16:15:34
 * @LastEditors: Please set LastEditors
 -->
<!doctype html>
<html>

<head>
    <meta charset="utf-8">
    <meta name="viewport"
        content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0" />
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <title>Hello APP</title>
    <link rel="stylesheet" type="text/css" href="../../css/vant_new.css">
    <link rel="stylesheet" type="text/css" href="../../css/base.css" />
    <script type="text/javascript" src="../../script/jquery.js"></script>
    <script type="text/javascript" src="../../script/layer/mobile/layer.js"></script>
    <script type="text/javascript" src="../../script/vue.min.js"></script>
    <script type="text/javascript" src="../../script/vant_new.min.js"></script>
    <script type="text/javascript" src="../../script/fastclick.js"></script>
    <script type="text/javascript" src="../../script/base.js"></script>
    <script type="text/javascript" src="../../script/formConfigDetail.js"></script>
    <script type="text/javascript" src="../../script/approvalRecord.js"></script>
    <script type="text/javascript" src="../../script/db.js"></script>
    <style type="text/css">
        .main-animate {
            overflow: hidden;
            transition: all .4s;
        }

        .hide {
            height: 0 !important;
        }

        .toggle-1 {
            text-align: center;
            padding: 10px 0;
        }

        .toggle-1 img {
            width: 20px;
            transition: all .4s;
        }

        .toggle-1 img.rotate {
            transform: rotate(180deg);
        }

        .required {
            color: #cd1b21;
            display: inline-block;
            width: 5px;
        }

        .hidden {
            visibility: hidden;
        }

        .item {
            border-bottom: 1px dashed #cd1b21;
        }

        .item:last-child {
            border-bottom: 0;
        }

        .col-border {
            position: relative;
        }

        .col-border::after {
            position: absolute;
            box-sizing: border-box;
            content: ' ';
            pointer-events: none;
            right: 0;
            bottom: 0;
            left: 16px;
            border-bottom: 1px solid #ebedf0;
            -webkit-transform: scaleY(0.5);
            transform: scaleY(0.5);
        }

        .p-select {
            padding: 0 30px 15px;
        }

        .p-select span,
        .p-select i {
            vertical-align: middle;
        }

        .title {
            float: left;
            font-weight: 700;
        }

        .main-right {
            float: right;
        }

        .delete {
            width: 20px;
            height: 16px;
            float: left;
        }

        .delete img {
            width: 16px;
            vertical-align: text-top;
        }

        .arrow-toggle {
            display: inline-block;
            margin-left: 12px;
            width: 24px;
            text-align: center;
        }

        .arrow-toggle img {
            width: 16px;
            vertical-align: middle;
        }

        .arrow-toggle img.rotate {
            width: 16px;
            vertical-align: middle;
            transform: rotate(180deg);
        }

        .detail {
            overflow: hidden;
            transition: all .4s;
        }

        textarea {
            padding-right: 30px !important;
        }

        .van-uploader__preview-delete {
            position: absolute;
            top: -8px;
            right: -8px;
            color: #969799;
            font-size: 18px;
            background-color: #fff;
            border-radius: 100%;
            height: 20px;
        }

        .van-uploader__preview-image {
            width: 80px;
            height: 80px;
        }

        .van-uploader__upload {
            width: 80px;
            height: 80px;
            /* background: #ebedf0;
            border:0; */
        }

        .form-line::after {
            position: absolute;
            box-sizing: border-box;
            content: ' ';
            pointer-events: none;
            right: 0;
            bottom: 0;
            left: 16px;
            border-bottom: 1px solid #ebedf0;
            -webkit-transform: scaleY(0.5);
            transform: scaleY(0.5);
        }

        .van-field__right-icon {
            position: absolute;
            right: 0;
            top: -10px;
            bottom: -10px;
            line-height: 44px;
            padding: 0 10px;
        }

        .van-field__label {
            width: 100px;
        }

        .label {
            font-size: 13px;
            font-weight: 700;
            color: #323233;
            padding-left: 15px;
            padding-top: 10px;
        }

        .approval {
            height: 100%;
        }

        .approval-head {
            text-align: center;
            height: 65px;
            line-height: 40px;
            font-size: 18px;
            font-weight: 700;
            color: #323233;
            padding: 25px 15px 0 55px;
        }

        .approval-close {
            float: right;
            width: 40px;
            height: 40px;
            text-align: center;
            line-height: 40px;
            color: #c8c9cc;
            font-size: 22px;
        }

        .approval-content {
            height: calc(100% - 65px);
            overflow-y: auto;
        }

        .approval-row {
            padding: 5px 15px;
        }

        .approval-row .pd {
            box-shadow: 0 0px 12px #dbdee2;
            border-radius: 8px;
            overflow: hidden;
        }

        .l-1 {
            background: url(../../image/left-top-1.png) no-repeat !important;
            background-size: 82px 100% !important;
            background-position: -3px -3px !important;
        }

        .van-radio{
            display: inline-block;
        }
        .van-radio__icon{
            display: inline-block;
            vertical-align: middle;
            font-size: 14px;
        }
        .van-radio__label{
            vertical-align: middle;
            font-size: 14px;
        }

        .van-checkbox{
            margin-bottom: 8px;
        }
        .van-checkbox__icon{
            font-size: 14px;
        }

        .van-checkbox__label{
            font-size: 14px;
        }
    </style>
</head>

<body>
    <div id="app" v-cloak>
        <div class="init-full" @click="clickDom($event)">
            <van-nav-bar class="head" :title="titleName" left-arrow @click-left="onClickLeft">
                <div slot="right" class="head-right">
                    <span @click.stop="showMenu = !showMenu">
                        <img src="../../image/menu.png" />
                    </span>
                </div>
            </van-nav-bar>
            <div class="body-with-bottom">
                <div class="content content-padding">
                    <div style="padding: 0 10px 15px;">
                        <div class="shadow">
                            <div class="content-label">基本信息</div>
                            <div v-for="(formRow,index1) in formDesign">
                                <div style="position: relative;" v-for="(formCol,index2) in formRow.controls"
                                    v-show="!formCol.baseProperty.isFold">
                                    <div class="form-line">
                                        <van-field v-if="formCol.baseProperty.controlType=='textbox'"
                                            :readonly="formCol.baseProperty.isReadOnly" @change="dataChange(formCol)"
                                            :placeholder="!formCol.baseProperty.isReadOnly?'请输入' + formCol.baseProperty.labelName:''"
                                            v-model="formData[formCol.baseProperty.controlName]">
                                            <div slot="label"><span
                                                    :class="formCol.baseProperty.isRequired?'required':'hidden'">*</span>{{formCol.baseProperty.labelName}}
                                            </div>
                                        </van-field>
                                        <div v-if="formCol.baseProperty.controlType=='textarea'">
                                            <div class="label"><span
                                                    :class="formCol.baseProperty.isRequired?'required':'hidden'">*</span>{{formCol.baseProperty.labelName}}
                                            </div>
                                            <van-field
                                                :placeholder="!formCol.baseProperty.isReadOnly?'请输入' + formCol.baseProperty.labelName:''"
                                                type="textarea" rows="2" autosize
                                                :readonly="formCol.baseProperty.isReadOnly"
                                                @change="dataChange(formCol)"
                                                v-model="formData[formCol.baseProperty.controlName]">
                                            </van-field>
                                        </div>

                                        <van-field v-else-if="formCol.baseProperty.controlType=='number'"
                                            :readonly="formCol.baseProperty.isReadOnly" @change="dataChange(formCol)"
                                            :placeholder="!formCol.baseProperty.isReadOnly?'请输入' + formCol.baseProperty.labelName:''"
                                            v-model="formData[formCol.baseProperty.controlName]" type="number">
                                            <div slot="label"><span
                                                    :class="formCol.baseProperty.isRequired?'required':'hidden'">*</span>{{formCol.baseProperty.labelName}}
                                            </div>
                                        </van-field>
                                        <van-cell v-else-if="formCol.baseProperty.controlType=='hidden'"
                                            :title="formCol.baseProperty.labelName"
                                            :value="formData[formCol.baseProperty.controlName]" style="display:none;">
                                        </van-cell>
                                        <van-cell
                                            v-else-if="formCol.baseProperty.controlType=='select' && formCol.controlProperty.select.type == 1 && (!formCol.controlProperty.select.showType || formCol.controlProperty.select.showType == 1)"
                                            :is-link="!formCol.baseProperty.isReadOnly" arrow-direction="down"
                                            @click="openSimpleSelect(index1,index2,formCol)">
                                            <div slot="title"><span
                                                    :class="formCol.baseProperty.isRequired?'required':'hidden'">*</span>{{formCol.baseProperty.labelName}}
                                            </div>
                                            <div style="color: #929292;"
                                                v-show="!formCol.baseProperty.isReadOnly && !getsimpleSelectText(index1,index2,formCol)">
                                                请选择{{formCol.baseProperty.labelName}}</div>
                                            <div v-show="getsimpleSelectText(index1,index2,formCol)">
                                                {{getsimpleSelectText(index1,index2,formCol)}}</div>
                                        </van-cell>





                                        <div v-else-if="formCol.baseProperty.controlType=='select' && formCol.controlProperty.select.type == 1 && formCol.controlProperty.select.showType == 2">
                                            <div class="label"><span
                                                    :class="formCol.baseProperty.isRequired?'required':'hidden'">*</span>{{formCol.baseProperty.labelName}}
                                            </div>
                                            <div style="padding: 8px 0 8px 16px;">
                                                <van-radio-group v-model="formData[formCol.baseProperty.controlName]" direction="horizontal">
                                                    <van-radio :name="checkItem[formCol.controlProperty.select.hiddenValue]" v-for="checkItem in setSimpleSelect(index1,index2,formCol)" style="margin-right: 12px;">{{checkItem[formCol.controlProperty.select.displayValue]}}</van-radio>
                                                  </van-radio-group>
                                            </div>
                                            
                                        </div>

                                        <div v-else-if="formCol.baseProperty.controlType=='select' && formCol.controlProperty.select.type == 1 && formCol.controlProperty.select.showType == 3">
                                            <div class="label"><span
                                                    :class="formCol.baseProperty.isRequired?'required':'hidden'">*</span>{{formCol.baseProperty.labelName}}(多选)
                                            </div>
                                            <div style="padding: 8px 0 8px 16px;">
                                                <!-- {{formData[formCol.baseProperty.controlName]}} -->
                                                <!-- <van-checkbox-group :value="formCol.controlProperty.select.actualName" direction="horizontal">
                                                    <van-checkbox shape="square" :name="checkItem[formCol.controlProperty.select.hiddenValue]" v-for="checkItem in setSimpleSelect(index1,index2,formCol)" style="margin-right: 12px;">{{checkItem[formCol.controlProperty.select.displayValue]}}</van-checkbox>
                                                  </van-checkbox-group> -->
                                                  <van-checkbox-group v-model="formCol.controlProperty.select.actualName" direction="horizontal" @change="changeCheckBoxValue(index1,index2,formCol)">
                                                    <van-checkbox shape="square" :name="checkItem[formCol.controlProperty.select.hiddenValue]" v-for="checkItem in setSimpleSelect(index1,index2,formCol)" style="margin-right: 12px;">{{checkItem[formCol.controlProperty.select.displayValue]}}</van-checkbox>
                                                  </van-checkbox-group>
                                            </div>
                                            
                                        </div>




                                        <van-cell
                                            v-else-if="formCol.baseProperty.controlType=='select' && formCol.controlProperty.select.type == 3"
                                            :is-link="!formCol.baseProperty.isReadOnly"
                                            @click="openComplexSelect(index1,index2,formCol)">
                                            <div slot="title"><span
                                                    :class="formCol.baseProperty.isRequired?'required':'hidden'">*</span>{{formCol.baseProperty.labelName}}
                                            </div>
                                            <div style="color: #929292;"
                                                v-show="!formCol.baseProperty.isReadOnly && !formCol.controlProperty.select.actualName">
                                                请选择{{formCol.baseProperty.labelName}}</div>
                                            <div v-show="formCol.controlProperty.select.actualName">
                                                {{formCol.controlProperty.select.actualName}}</div>
                                        </van-cell>
                                        <van-cell v-else-if="formCol.baseProperty.controlType=='datepicker'"
                                            :readonly="formCol.baseProperty.isReadOnly"
                                            :value="(formData[formCol.baseProperty.controlName] || '').replace(/T/g,' ')"
                                            @click="openDatePicker(index1,index2,formCol)">

                                            <div slot="title"><span
                                                    :class="formCol.baseProperty.isRequired?'required':'hidden'">*</span>{{formCol.baseProperty.labelName}}
                                            </div>
                                            <van-icon v-if="!formCol.baseProperty.isReadOnly" slot="right-icon"
                                                name="../../image/date.png" size="18" style="line-height: inherit;">
                                            </van-icon>

                                            <div style="color: #929292;"
                                                v-show="!formCol.baseProperty.isReadOnly && !formData[formCol.baseProperty.controlName]">
                                                请选择{{formCol.baseProperty.labelName}}</div>
                                            <div v-show="formData[formCol.baseProperty.controlName]">
                                                {{(formData[formCol.baseProperty.controlName] || '').replace(/T/g,' ')}}
                                            </div>
                                        </van-cell>
                                        <van-field v-else-if="formCol.baseProperty.controlType=='map'" type="textarea"
                                            rows="1" :autosize="{minHeight:24}" readonly
                                            :placeholder="!formCol.baseProperty.isReadOnly?'请输入' + formCol.baseProperty.labelName:''"
                                            v-model="formData[formCol.baseProperty.controlName]" clearable>
                                            <div slot="label"><span
                                                    :class="formCol.baseProperty.isRequired?'required':'hidden'">*</span>{{formCol.baseProperty.labelName}}
                                            </div>
                                            <div slot="right-icon" @click="getLocation(formCol)">
                                                <van-icon name="location"></van-icon>
                                            </div>
                                        </van-field>
                                        <van-cell v-else-if="formCol.baseProperty.controlType=='fileUpload'">
                                            <div slot="title"><span
                                                    :class="formCol.baseProperty.isRequired?'required':'hidden'">*</span>{{formCol.baseProperty.labelName}}
                                            </div>
                                            <div style="padding-top: 10px;">
                                                <div class="van-uploader">
                                                    <div class="van-uploader__wrapper">
                                                        <div class="van-uploader__preview"
                                                            v-for="(imgItem,imgItemIndex) in getSplitImg(formData[formCol.baseProperty.controlName])">
                                                            <div class="van-image van-uploader__preview-image"
                                                                style="overflow: hidden; border-radius: 4px;"
                                                                @click="previewImage(formCol,imgItemIndex)">

                                                                <img :src="serverIP + imgItem" class="van-image__img"
                                                                    style="object-fit: cover;" />
                                                            </div>
                                                            <i class="van-icon van-icon-clear van-uploader__preview-delete"
                                                                @click="deleteImgItem(formCol.baseProperty.controlName,imgItemIndex)"></i>
                                                        </div>
                                                        <div class="van-uploader__upload"
                                                            v-if="(formCol.controlProperty.upload.isMulti && getSplitImg(formData[formCol.baseProperty.controlName]).length < 9) || getSplitImg(formData[formCol.baseProperty.controlName]).length == 0"
                                                            @click="addImage(formCol,getSplitImg(formData[formCol.baseProperty.controlName]).length)">
                                                            <i class="van-icon van-icon-plus van-uploader__upload-icon"
                                                                v-if="!formCol.baseProperty.defaultValue"></i>
                                                            <img style="width:50px;"
                                                                :src="serverIP + formCol.baseProperty.defaultValue"
                                                                v-if="formCol.baseProperty.defaultValue" />

                                                        </div>
                                                    </div>
                                                </div>
                                            </div>
                                        </van-cell>
                                    </div>

                                </div>
                            </div>
                            <div class="main-animate" :class="!showMain?'hide':''"
                                :style="{height:animateHeight + 'px'}">
                                <div v-for="(formRow,index1) in formDesign">

                                    <div style="position: relative;" v-for="(formCol,index2) in formRow.controls"
                                        v-show="formCol.baseProperty.isFold">
                                        <div class="form-line">
                                            <van-field v-if="formCol.baseProperty.controlType=='textbox'"
                                                :readonly="formCol.baseProperty.isReadOnly"
                                                @change="dataChange(formCol)"
                                                :placeholder="!formCol.baseProperty.isReadOnly?'请输入' + formCol.baseProperty.labelName:''"
                                                v-model="formData[formCol.baseProperty.controlName]">
                                                <div slot="label"><span
                                                        :class="formCol.baseProperty.isRequired?'required':'hidden'">*</span>{{formCol.baseProperty.labelName}}
                                                </div>
                                            </van-field>
                                            <div v-if="formCol.baseProperty.controlType=='textarea'">
                                                <div class="label"><span
                                                        :class="formCol.baseProperty.isRequired?'required':'hidden'">*</span>{{formCol.baseProperty.labelName}}
                                                </div>
                                                <van-field
                                                    :placeholder="!formCol.baseProperty.isReadOnly?'请输入' + formCol.baseProperty.labelName:''"
                                                    type="textarea" rows="2" autosize
                                                    :readonly="formCol.baseProperty.isReadOnly"
                                                    @change="dataChange(formCol)"
                                                    v-model="formData[formCol.baseProperty.controlName]">
                                                </van-field>
                                            </div>
                                            <van-field v-else-if="formCol.baseProperty.controlType=='number'"
                                                :readonly="formCol.baseProperty.isReadOnly"
                                                @change="dataChange(formCol)"
                                                :placeholder="!formCol.baseProperty.isReadOnly?'请输入' + formCol.baseProperty.labelName:''"
                                                v-model="formData[formCol.baseProperty.controlName]" type="number">
                                                <div slot="label"><span
                                                        :class="formCol.baseProperty.isRequired?'required':'hidden'">*</span>{{formCol.baseProperty.labelName}}
                                                </div>
                                            </van-field>
                                            <van-cell v-else-if="formCol.baseProperty.controlType=='hidden'"
                                                :title="formCol.baseProperty.labelName"
                                                :value="formData[formCol.baseProperty.controlName]"
                                                style="display:none;">
                                            </van-cell>
                                            <van-cell
                                                v-else-if="formCol.baseProperty.controlType=='select' && formCol.controlProperty.select.type == 1"
                                                :is-link="!formCol.baseProperty.isReadOnly" arrow-direction="down"
                                                @click="openSimpleSelect(index1,index2,formCol)">
                                                <div slot="title"><span
                                                        :class="formCol.baseProperty.isRequired?'required':'hidden'">*</span>{{formCol.baseProperty.labelName}}
                                                </div>
                                                <div style="color: #929292;"
                                                    v-show="!formCol.baseProperty.isReadOnly && !getsimpleSelectText(index1,index2,formCol)">
                                                    请选择{{formCol.baseProperty.labelName}}</div>
                                                <div v-show="getsimpleSelectText(index1,index2,formCol)">
                                                    {{getsimpleSelectText(index1,index2,formCol)}}</div>
                                            </van-cell>
                                            <van-cell
                                                v-else-if="formCol.baseProperty.controlType=='select' && formCol.controlProperty.select.type == 3"
                                                :is-link="!formCol.baseProperty.isReadOnly"
                                                @click="openComplexSelect(index1,index2,formCol)">
                                                <div slot="title"><span
                                                        :class="formCol.baseProperty.isRequired?'required':'hidden'">*</span>{{formCol.baseProperty.labelName}}
                                                </div>
                                                <div style="color: #929292;"
                                                    v-show="!formCol.baseProperty.isReadOnly && !formCol.controlProperty.select.actualName">
                                                    请选择{{formCol.baseProperty.labelName}}</div>
                                                <div v-show="formCol.controlProperty.select.actualName">
                                                    {{formCol.controlProperty.select.actualName}}</div>
                                            </van-cell>
                                            <van-cell v-else-if="formCol.baseProperty.controlType=='datepicker'"
                                                :readonly="formCol.baseProperty.isReadOnly"
                                                :value="(formData[formCol.baseProperty.controlName] || '').replace(/T/g,' ')"
                                                @click="openDatePicker(index1,index2,formCol)">

                                                <div slot="title"><span
                                                        :class="formCol.baseProperty.isRequired?'required':'hidden'">*</span>{{formCol.baseProperty.labelName}}
                                                </div>
                                                <van-icon v-if="!formCol.baseProperty.isReadOnly" slot="right-icon"
                                                    name="../../image/date.png" size="18" style="line-height: inherit;">
                                                </van-icon>

                                                <div style="color: #929292;"
                                                    v-show="!formCol.baseProperty.isReadOnly && !formData[formCol.baseProperty.controlName]">
                                                    请选择{{formCol.baseProperty.labelName}}</div>
                                                <div v-show="formData[formCol.baseProperty.controlName]">
                                                    {{(formData[formCol.baseProperty.controlName] || '').replace(/T/g,' ')}}
                                                </div>
                                            </van-cell>
                                            <van-field v-else-if="formCol.baseProperty.controlType=='map'"
                                                type="textarea" rows="1" :autosize="{minHeight:24}" readonly
                                                :placeholder="!formCol.baseProperty.isReadOnly?'请输入' + formCol.baseProperty.labelName:''"
                                                v-model="formData[formCol.baseProperty.controlName]" clearable>
                                                <div slot="label"><span
                                                        :class="formCol.baseProperty.isRequired?'required':'hidden'">*</span>{{formCol.baseProperty.labelName}}
                                                </div>
                                                <div slot="right-icon" @click="getLocation(formCol)">
                                                    <van-icon name="location"></van-icon>
                                                </div>
                                            </van-field>
                                            <van-cell v-else-if="formCol.baseProperty.controlType=='fileUpload'">
                                                <div slot="title"><span
                                                        :class="formCol.baseProperty.isRequired?'required':'hidden'">*</span>{{formCol.baseProperty.labelName}}
                                                </div>
                                                <div style="padding-top: 10px;">
                                                    <div class="van-uploader">
                                                        <div class="van-uploader__wrapper">
                                                            <div class="van-uploader__preview"
                                                                v-for="(imgItem,imgItemIndex) in getSplitImg(formData[formCol.baseProperty.controlName])">
                                                                <div class="van-image van-uploader__preview-image"
                                                                    style="overflow: hidden; border-radius: 4px;"
                                                                    @click="previewImage(formCol,imgItemIndex)">

                                                                    <img :src="serverIP + imgItem"
                                                                        class="van-image__img"
                                                                        style="object-fit: cover;" />
                                                                </div>
                                                                <i class="van-icon van-icon-clear van-uploader__preview-delete"
                                                                    @click="deleteImgItem(formCol.baseProperty.controlName,imgItemIndex)"></i>
                                                            </div>
                                                            <div class="van-uploader__upload"
                                                                v-if="(formCol.controlProperty.upload.isMulti || (getSplitImg(formData[formCol.baseProperty.controlName]).length == 0 && !formCol.controlProperty.upload.isMulti)) && !keyValue"
                                                                @click="addImage(formCol,getSplitImg(formData[formCol.baseProperty.controlName]).length)">
                                                                <!-- <span>{{getFileText(formCol.baseProperty.labelName)}}</span> -->
                                                                <i class="van-icon van-icon-plus van-uploader__upload-icon"
                                                                    v-if="!formCol.baseProperty.defaultValue"></i>
                                                                <img style="width:50px;"
                                                                    :src="serverIP + formCol.baseProperty.defaultValue"
                                                                    v-if="formCol.baseProperty.defaultValue" />
                                                                <!-- <div style="color:#9e9e9e;letter-spacing: 2px;">{{getFileText(formCol.baseProperty.labelName)}}</div> -->

                                                            </div>
                                                        </div>
                                                    </div>
                                                </div>
                                            </van-cell>
                                        </div>

                                    </div>
                                </div>
                            </div>

                            <div class="toggle-1" @click="toggleShowMain">
                                <img src="../../image/retract.png" :class="!showMain?'rotate':''" />
                            </div>
                        </div>
                    </div>
                    <div v-for="(childForm,index) in childFormList">
                        <form-detail :ref="'detail' + index" :modulename="childForm.name" :keyname="keyName"
                            :keyvalue="keyValue" :objname="objName" :draftkey="draftID"></form-detail>
                    </div>

                    <div style="padding: 0 10px 15px;" v-if="keyValue && isApproval">
                        <div class="shadow">

                            <div class="content-label l-1">审批记录</div>
                            <form-approval ref="approval" :billquery="billquery"></form-approval>
                            <div class="btn-padding"
                                v-if="approvalData && isUpdate && isUnWorkRoleList(approvalData.name) && btn_showCondition(2,approvalData)">
                                <van-button :disabled="ifConfirm" :loading="ifConfirm" loading-text="审批提交中..."
                                    type="primary" block @click="selfWorkHandler(approvalData)">审批</van-button>
                            </div>

                        </div>
                    </div>


                </div>
                <van-loading v-if="showLoading" />
            </div>
            <div class="bottom">
                <div class="bottom-left-label">
                    <span v-for="row in summaryData">
                        <span>合计{{row.desc}}:</span>
                        <span class="number">{{row.value}}</span>
                    </span>

                </div>
                <div class="bottom-right-button">
                    <van-button :disabled="ifConfirm || (showApprovalSuccess() && showApprovalImg(1))"
                        :loading="ifConfirm" loading-text="数据提交中..." type="primary" block @click="confirmForm">
                        {{(showApprovalSuccess() && showApprovalImg(1))?'已过账':'提交'}}</van-button>
                </div>
            </div>
        </div>

        <van-popup v-model="showSimpleSelect" position="bottom" v-if="formDesign[simpleSelectIndex[0]]">
            <van-picker show-toolbar :columns="columns"
                :value-key="formDesign[simpleSelectIndex[0]].controls[simpleSelectIndex[1]].controlProperty.select.displayValue"
                @cancel="showSimpleSelect = false" @confirm="simpleSelectChange"></van-picker>
        </van-popup>

        <van-popup v-model="showDatePicker" position="bottom" v-if="formDesign[simpleSelectIndex[0]]">
            <van-datetime-picker v-model="currentDate" cancel-button-text="清空"
                :type="formDesign[simpleSelectIndex[0]].controls[simpleSelectIndex[1]].controlProperty.date.type == 'datetime'?'datetime':'date'"
                @cancel="clearDatePicker" @confirm="confirmDatePicker" />
        </van-popup>

        <van-dialog v-model="showApproval" show-cancel-button close-on-click-overlay confirm-button-text="通过"
            cancel-button-text="不通过" @confirm="approvalConfirm(1)" @cancel="approvalConfirm(2)">
            <div style="padding-top:10px;">
                <div style="color: #cd1b21;font-size:13px;line-height: 30px;padding-left:15px;" v-show="approvalTitle">
                    审核提示：{{approvalTitle}}</div>
                <van-field label="原因" v-model="approvalReason" placeholder="请输入审批通过/不通过原因"></van-field>
            </div>
        </van-dialog>





        <!-- 拣货出库专用 -->
        <van-popup v-model="showDistribute" round position="bottom">
            <div>
                <van-cell title="拣货人员" :value="distribute.personName" is-link arrow-direction="down"
                    @click="showDistributeList = true;">
                </van-cell>
            </div>
            <div class="btn-padding">
                <van-button type="primary" block style="border-radius: 0;" @click="distributeSubmit">提交</van-button>
            </div>
        </van-popup>


        <van-popup v-model="showDistributeList" position="bottom">
            <van-picker show-toolbar :columns="distributeList" value-key="Name" @cancel="showDistributeList = false;"
                @confirm="confirmDistributeList" v-if="distributeList.length"></van-picker>
        </van-popup>
        <!-- 拣货出库专用 -->

        <!-- <van-popup v-model="isShowApproval" position="bottom" :style="{ height: '100%' }">
            <div class="approval-head">审批记录<div class="approval-close" @click="isShowApproval = false;">
                    <van-icon name="cross"></van-icon>
                </div>
            </div>
            <form-approval ref="approval" :billquery="billquery" v-if="isShowApproval"></form-approval>
        </van-popup> -->

        <div class="head-menu" v-if="showMenu">
            <img class="menu-arrow" src="../../image/menu-arrow.png" />
            <div v-for="work in workList" v-if="isUpdate && isUnWorkRoleList(work.name) && btn_showCondition(2,work) "
                @click="selfWorkHandler(work)">
                <img src="../../image/yw.png" />
                <span>{{work.name}}</span>
            </div>
            <div v-for="config in topImportConfig" v-if="btn_showCondition(3,config)"
                @click="selfImportHandler(config)">
                <img src="../../image/yw.png" />
                <span>{{config.btnName}}</span>
            </div>
            <!-- <div @click="isShowApproval = true;" v-if="keyValue && isApproval">
                <img src="../../image/history.png" />
                <span>审批记录</span>
            </div> -->
            <div @click="printView" v-if="objName == 'app_委托代销出库' && keyValue">
                <img src="../../image/history.png" />
                <span>打印</span>
            </div>
            <div @click="openHistory">
                <img src="../../image/history.png" />
                <span>历史单据</span>
            </div>
            <!-- <div @click="openDraft" v-show="!draftID">
                <img src="../../image/draft-list.png" />
                <span>历史草稿</span>
            </div>
            <div @click="saveLocal">
                <img src="../../image/draft.png" />
                <span>保存草稿</span>
            </div> -->
        </div>



    </div>
</body>

<script type="text/javascript">
    var vm, approvalCallBack;
    function layerSelfAlert(msg) {
        layer.open({
            content: msg,
            skin: 'msg',
            time: 2
        });
    }
    apiready = function () {
        //$('.init-full').show();
        var userInfo = FLD.getUserInfo();
        //复杂下拉选单选选中
        api.addEventListener({
            name: 'selectRow'
        }, function (ret, err) {
            var row = ret.value.row;
            var formCol = vm.formDesign[vm.simpleSelectIndex[0]].controls[vm.simpleSelectIndex[1]];
            vm.formData[formCol.baseProperty.controlName] = row[formCol.controlProperty.select.hiddenValue];
            formCol.controlProperty.select.actualName = row[formCol.controlProperty.select.displayValue];
            vm.selectData[formCol.baseProperty.controlName] = row;
            vm.$set(formCol.controlProperty.select, "sqlDataSource", [row]);
            vm.$set(formCol.controlProperty.select, "originDataSource", [row]);

            if (formCol.controlProperty.select.change != "") {
                vm.selectDataChange(formCol);
            }

            if (formCol.baseProperty.controlCallBack) {
                var script = formCol.baseProperty.controlCallBack.replace(/\['/g, "vm.formData['");
                script = script.replace(/\["/g, "vm.formData[\"");
                script = script.replace(/layer.msg/g, "layerSelfAlert");
                eval(script);
                vm.refreshInitActualName();
            }
        })

        //复杂下拉选单选选中
        api.addEventListener({
            name: 'selectArray'
        }, function (ret, err) {
            var array = ret.value.array;
            var formCol = vm.formDesign[vm.simpleSelectIndex[0]].controls[vm.simpleSelectIndex[1]];
            if (formCol.controlProperty.select.chooseType == 3) {
                var idArray = [];
                var textArray = [];
                for (var i in array) {
                    idArray.push(array[i][formCol.controlProperty.select.hiddenValue])
                    textArray.push(array[i][formCol.controlProperty.select.displayValue])
                }
                vm.formData[formCol.baseProperty.controlName] = idArray.join();
                formCol.controlProperty.select.actualName = textArray.join();
                vm.selectDataChange(formCol);
            }
        })

        api.addEventListener({
            name: 'selectImportData'
        }, function (ret, err) {
            var columns = ret.value.columns;
            var selections = ret.value.selections;
            vm.importData(columns, selections)
        })

        var map = api.require('bMap');
        if (api.systemType == 'android') {
			map.setAgreePrivacy({
			agree:true
		});	
		}
        // if (api.systemType == 'ios') {
            map.initMapSDK(function (ret) { });
        // }

        var UIAlbumBrowser = api.require('UIAlbumBrowser');
        var photoBrowser = api.require('photoBrowser');


        vm = new Vue({
            el: '#app',
            data: {

                showLoading: false,
                ifConfirm: false,
                //是否显示简单下拉选
                showSimpleSelect: false,
                //简单下拉选的数组列表
                columns: [],
                //打开下拉选或者日期选择时，所指向的表单列
                simpleSelectIndex: [0, 0],
                //是否显示时间选择器
                showDatePicker: false,
                //打开时间选择器时,选中的时间
                currentDate: new Date(),
                showMain: false,
                animateHeight: 0,
                serverIP: 'http://' + FLD.serverIP,
                summaryData: [],

                showMenu: false,
                approvalTitle: '',
                approvalReason: '',
                showApproval: false,
                titleName: api.pageParam.titleName || '',
                keyName: api.pageParam.keyName || '',
                keyValue: api.pageParam.keyValue || 0,
                objName: api.pageParam.objName,
                draftID: api.pageParam.draftID || 0,
                // isPosted: api.pageParam.isPosted || false,

                isNew: api.pageParam.keyValue ? false : true,

                childFormList: [],
                formDesign: [],
                formData: {},
                physicalTableName: "",
                isUpdate: false,
                workList: [],
                crudList: [],
                topImportConfig: [],
                detailImportConfig: [],
                currentFileUpload: undefined,
                parentWindow: undefined,
                parentWindowIndex: -1,
                childFormSelectName: "",
                isApproval: false,
                currentControlName: '',
                currentControl: {},
                isInitPage: true,
                //首次
                isFirstPage: true,
                //禁用业务流禁用数组
                unWorkRoleList: [],
                //用于记忆的查询数组
                changeDataSource: [],
                tableData: [],
                selectData: {},
                isShowApproval: false,
                billquery: '',

                distribute: {
                    personName: '',
                    personID: 0
                },
                distributeList: [],
                showDistributeList: false,
                showDistribute: false,
                approvalData:''
            },
            watch: {
                formData: {
                    handler(val, oldVal) {
                        //首次更新不进来
                        if (!this.isFirstPage) {
                            this.transParamsDefault();
                        }
                    },
                    deep: true
                }
            },
            created() {
                this.refreshPage();

            },
            methods: {
                // app逻辑
                //---------------------------
                confirmDistributeList(value, index) {
                    var that = this;
                    that.distribute.personName = that.distributeList[index].Name;
                    that.distribute.personID = that.distributeList[index].Id;
                    that.showDistributeList = false;
                },
                distributeSubmit() {
                    var that = this;
                    that.showDistribute = false;
                    var obj = {
                        S_BType: -1,
                        S_KeyID: that.keyValue,
                        S_UserID: that.distribute.personID,
                        S_BillType: 2301
                    }
                    that.ifConfirm = true;
                    FLD.ajax('APP_JHJKCLNMX', obj, function (res) {
                        that.ifConfirm = false;
                        if (res.ds[0].status == 200) {
                            that.distribute.personID = 0;
                            that.distribute.personName = '';
                            layer.open({
                                content: '拣货出库成功',
                                skin: 'msg',
                                time: 2
                            });
                        } else {
                            layer.open({
                                content: res.ds[0].msg,
                                skin: 'msg',
                                time: 2
                            });
                        }
                    })
                },
                getFileText(t) {
                    var strArray = t.match(/图片\((\S*)\)/) || [];
                    if (strArray.length > 1) {
                        return strArray[1];
                    } else {
                        return t;
                    }
                },
                clickDom(e) {
                    if (!$(e.target).closest('.head-menu').length) {
                        this.showMenu = false;
                    }
                },
                getSplitImg(str) {
                    var that = this;
                    if (str) {
                        return str.split(',');
                    } else {
                        return [];
                    }
                },
                deleteImgItem(formDataLabel, index) {
                    var that = this;
                    var array = [];
                    if (that.formData[formDataLabel]) {
                        array = that.formData[formDataLabel].split(',');
                    }
                    array.splice(index, 1);
                    that.formData[formDataLabel] = array.join();
                },
                previewImage(formCol, index) {
                    var that = this;
                    var array = that.formData[formCol.baseProperty.controlName].split(',');
                    for (var i in array) {
                        array[i] = that.serverIP + array[i];
                    }
                    photoBrowser.open({
                        images: array,
                        activeIndex: index,
                        bgColor: '#000'
                    }, function (ret) {
                        if (ret) {
                            if (ret.eventType == 'click') {
                                photoBrowser.close();
                            }
                        }
                    })
                },
                addImage(formCol,len) {
                    var isMulti = formCol.controlProperty.upload.isMulti;
                    var that = this;
                    UIAlbumBrowser.imagePicker({
                        max: isMulti ? (9 - len) : 1,
                        styles: {
                            nav: {
                                bg: 'rgba(0,0,0,.6)',
                                finishText: '完成'
                            }
                        },
                        rotation: true
                    }, function (ret) {
                        if (ret) {
                            if (ret.originalPath) {
                                // UIAlbumBrowser.closePicker();
                                UIAlbumBrowser.transPath({
                                    path: ret.assetPath || ret.originalPath
                                }, function (ret, err) {
                                    if (ret) {
                                        FLD.uploadFile('配置表单图片', ret.path, function (path) {
                                            if (that.formData[formCol.baseProperty.controlName]) {
                                                that.formData[formCol.baseProperty.controlName] = that.formData[formCol.baseProperty.controlName] + ',' + path;
                                            } else {
                                                that.formData[formCol.baseProperty.controlName] = path;
                                            }
                                        })

                                    }
                                });
                            } else if (ret.eventType == 'nextStep') {
                                UIAlbumBrowser.closePicker();
                                var imgLists = ret.list;
                                var repeatImg = function (i) {
                                    if (i == imgLists.length) {
                                        return;
                                    }
                                    UIAlbumBrowser.transPath({
                                        path: imgLists[i].path
                                    }, function (ret, err) {
                                        if (ret) {
                                            FLD.uploadFile('配置表单图片', ret.path, function (path) {
                                                if (that.formData[formCol.baseProperty.controlName]) {
                                                    that.formData[formCol.baseProperty.controlName] = that.formData[formCol.baseProperty.controlName] + ',' + path;
                                                } else {
                                                    that.formData[formCol.baseProperty.controlName] = path;
                                                }
                                            })
                                            i++;
                                            repeatImg(i);
                                        }
                                    });
                                }
                                repeatImg(0)

                            }

                        }
                    });
                },
                getLocation(formCol) {
                    var that = this;
                    map.getLocation({
                        accuracy: '10m',
                        autoStop: true
                    }, function (ret, err) {
                        map.getNameFromCoords({
                            lon: ret.lon,
                            lat: ret.lat
                        }, function (ret, err) {
                            that.formData[formCol.baseProperty.controlName] = ret.address;
                            that.dataChange(formCol);
                        });
                    })

                },
                toggleShowMain() {
                    var that = this;
                    that.showMain = !that.showMain;
                },
                //简单下拉选根据id显示text
                getsimpleSelectText(index1, index2, formCol) {
                    var that = this;
                    var sqlDataSource = formCol.controlProperty.select.sqlDataSource;
                    var txt = '';
                    for (var i in sqlDataSource) {
                        if (sqlDataSource[i][that.formDesign[index1].controls[index2].controlProperty.select.hiddenValue] === that.formData[formCol.baseProperty.controlName]) {
                            txt = sqlDataSource[i][that.formDesign[index1].controls[index2].controlProperty.select.displayValue];
                        }
                    }
                    return txt || '';
                },
                setSimpleSelect(index1, index2, formCol){
                    var that = this;
                    if (formCol.baseProperty.isReadOnly) {
                        return false;
                    }
                    var columns = formCol.controlProperty.select.sqlDataSource;
                    for (var i in columns) {
                        if (columns[i][that.formDesign[that.simpleSelectIndex[0]].controls[that.simpleSelectIndex[1]].controlProperty.select.displayValue] === null) {
                            columns[i][that.formDesign[that.simpleSelectIndex[0]].controls[that.simpleSelectIndex[1]].controlProperty.select.displayValue] = '';
                        }
                    }
                    return columns;
                },
                changeCheckBoxValue(index1, index2, formCol){
                    var that = this;
                    that.formData[formCol.baseProperty.controlName] = formCol.controlProperty.select.actualName
                },
                //打开简单下拉选
                openSimpleSelect(index1, index2, formCol) {
                    var that = this;
                    if (formCol.baseProperty.isReadOnly) {
                        return false;
                    }
                    that.simpleSelectIndex = [index1, index2]
                    that.columns = formCol.controlProperty.select.sqlDataSource;
                    for (var i in that.columns) {
                        if (that.columns[i][that.formDesign[that.simpleSelectIndex[0]].controls[that.simpleSelectIndex[1]].controlProperty.select.displayValue] === null) {
                            that.columns[i][that.formDesign[that.simpleSelectIndex[0]].controls[that.simpleSelectIndex[1]].controlProperty.select.displayValue] = '';
                        }
                    }
                    that.showSimpleSelect = true;
                },
                //简单下拉选选中
                simpleSelectChange(value, index) {
                    var that = this;
                    var formCol = that.formDesign[that.simpleSelectIndex[0]].controls[that.simpleSelectIndex[1]];
                    that.formData[formCol.baseProperty.controlName] = formCol.controlProperty.select.sqlDataSource[index][formCol.controlProperty.select.hiddenValue];
                    that.showSimpleSelect = false;

                    that.selectDataChange(formCol);
                },
                //打开复杂下拉选
                openComplexSelect(index1, index2, formCol) {
                    var that = this;
                    if (formCol.baseProperty.isReadOnly) {
                        return false;
                    }
                    that.simpleSelectIndex = [index1, index2];
                    var filter = formCol.controlProperty.select.formSQL;
                    for (var key in that.formData) {
                        var value = "'" + that.formData[key] + "'";
                        filter = eval("filter.replace(/" + "@" + key + "/g,value)")
                    }

                    api.openWin({
                        name: '复杂筛选' + formCol.controlProperty.url,
                        url: 'formConfigScreen.html',
                        reload: true,
                        slidBackEnabled: false,
                        pageParam: {
                            filter: filter,
                            screenName: formCol.controlProperty.select.url,
                            allowClear: true,
                            type: formCol.controlProperty.select.chooseType,
                            isDetail: false,
                            objName: that.objName
                        }
                    })
                },
                //打开日期选择器
                openDatePicker(index1, index2, formCol) {
                    var that = this;
                    if (formCol.baseProperty.isReadOnly) {
                        return false;
                    }
                    that.simpleSelectIndex = [index1, index2];
                    if (that.formData[formCol.baseProperty.controlName]) {
                        that.currentDate = new Date(that.formData[formCol.baseProperty.controlName].replace(/-/g, '/'));
                    } else {
                        that.currentDate = new Date();
                    }

                    that.showDatePicker = true;

                },
                //清空所选日期
                clearDatePicker() {
                    var that = this;
                    var formCol = that.formDesign[that.simpleSelectIndex[0]].controls[that.simpleSelectIndex[1]];
                    that.formData[formCol.baseProperty.controlName] = '';
                    that.showDatePicker = false;
                    that.dataChange(formCol);
                },
                //确认当前所选日期
                confirmDatePicker(value) {
                    var that = this;
                    var formCol = that.formDesign[that.simpleSelectIndex[0]].controls[that.simpleSelectIndex[1]];
                    if (formCol.controlProperty.date.type == 'datetime') {
                        that.formData[formCol.baseProperty.controlName] = FLD.getFormatDateTime(value);
                    } else {
                        that.formData[formCol.baseProperty.controlName] = FLD.getFormatDate(value).split(' ')[0];
                    }

                    that.showDatePicker = false;
                    that.dataChange(formCol);
                },
                //子表新增
                openDetailSelect() {
                    var that = this;
                    api.openWin({
                        name: '子表',
                        url: 'formConfigScreen.html',
                        reload: true,
                        slidBackEnabled: false,
                        pageParam: {
                            sqlData: '',
                            screenName: '分支机构表单',
                            allowClear: false,
                            type: 2,
                            objName: that.objName
                        }
                    })
                },
                printView() {
                    var that = this;
                    FLD.ajax('APP_APWTDXDYN', { S_KeyID: that.keyValue }, function (res) {
                        var formData = res.ds[0];
                        var formDetailData = res.ds1;

                        var nodeArray = [];
                        var totalNum = 0;
                        var totalPrice = 0;
                        for (var i in formDetailData) {
                            totalNum += formDetailData[i]['数量'];
                            totalPrice += formDetailData[i]['金额'];
                            nodeArray.push({
                                '名称': formDetailData[i]['商品名称'],
                                '规格': formDetailData[i]['商品规格'],
                                '单位': formDetailData[i]['单位'],
                                '数量': formDetailData[i]['数量'],
                                '单价': formDetailData[i]['单价'],
                                '金额': formDetailData[i]['金额'],

                            }, {
                                '备注': formDetailData[i]['备注说明']
                            })
                        }


                        var printData = {
                            title: '福路德汽配连锁',
                            subtitle: '委托代销-随货同行单',
                            top: {
                                '单据号': formData['单据号'],
                                '仓库': formData['仓库'],
                                '录单日期': formData['录单日期'],
                                '客户': formData['客户'],
                                '经手人': formData['经手人'],
                                '地址': formData['地址'],
                                '应收余额': formData['应收余额'],
                                '备注': formData['备注'],
                            },
                            node: nodeArray,
                            center: {
                                '合计数量': totalNum,
                                '合计金额': totalPrice,
                            },
                            bottom: {
                                '制单人': formData['制单人'],
                                '审核人': formData['审核人'],
                                '公司地址': formData['公司地址'],
                                '联系人': formData['联系人'],
                                '联系方式': formData['联系方式'],
                            }


                        }


                        window.localStorage.setItem('printData', JSON.stringify(printData));
                        api.openWin({
                            name: '打印预览',
                            url: 'printPreview.html',
                            reload: true,
                            slidBackEnabled: false
                        })

                    })



                },
                //打开历史记录
                openHistory() {
                    var that = this;
                    that.showMenu = false;
                    api.openWin({
                        name: 'formHistoricalDocuments',
                        url: 'formHistoricalDocuments.html',
                        reload: true,
                        slidBackEnabled: false,
                        pageParam: {
                            objName: that.objName + '主表',
                            titleName: that.objName.replace(/app_/g, '') + '历史'
                        }
                    })
                },
                //接收组件合计字段
                setBottomTotalParam(data) {
                    var that = this;
                    that.summaryData = data;
                },
                //接收组件合计数据
                getBottomTotal() {
                    var that = this;
                    var tableData = JSON.parse(JSON.stringify(that.$refs['detail0'][0].tableData))
                    for (var i in that.summaryData) {
                        var totalNum = 0;
                        for (var j in tableData) {
                            totalNum += Number(tableData[j][that.summaryData[i].name]);
                        }
                        that.summaryData[i].value = totalNum;
                    }


                },
                openDraft() {
                    var that = this;
                    that.showMenu = false;
                    api.openWin({
                        name: 'formConfigDraft',
                        url: 'formConfigDraft.html',
                        reload: true,
                        slidBackEnabled: false,
                        pageParam: {
                            objName: that.objName
                        }
                    })
                },
                saveLocal() {
                    var that = this;
                    that.showMenu = false;
                    var jsonstr1 = JSON.stringify(that.formData).replace(/\'/g, '\'\'');
                    var jsonstr2 = JSON.stringify(that.$refs['detail0'][0].tableData).replace(/\'/g, '\'\'');
                    var Remark = that.objName;
                    var json3 = [];
                    for (var index1 in that.formDesign) {
                        var formRow = that.formDesign[index1]
                        for (var index2 in formRow.controls) {
                            var formCol = formRow.controls[index2]
                            if (formCol.baseProperty.isRequired && formCol.baseProperty.controlType != 'hidden' && formCol.baseProperty.controlType != 'datepicker') {
                                if (formCol.baseProperty.controlType == 'select') {
                                    if (formCol.controlProperty.select.type == 1) {
                                        json3.push({
                                            name: formCol.baseProperty.labelName,
                                            value: that.getsimpleSelectText(index1, index2, formCol)
                                        })
                                    } else if (formCol.controlProperty.select.type == 3) {
                                        json3.push({
                                            name: formCol.baseProperty.labelName,
                                            value: formCol.controlProperty.select.actualName || ''
                                        })
                                    }
                                } else {
                                    json3.push({
                                        name: formCol.baseProperty.labelName,
                                        value: that.formData[formCol.baseProperty.controlName]
                                    })
                                }
                            }
                        }
                    }
                    var jsonstr3 = JSON.stringify(json3).replace(/\'/g, '\'\'');
                    if (that.draftID) {
                        var sql = "update Draft set JSONStr1='" + jsonstr1 + "',JSONStr2='" + jsonstr2 + "',JSONStr3='" + jsonstr3 + "',UpdateTime='" + FLD.getFormatDate() + "' where DraftID='" + that.draftID + "'";

                        DB.executeSql(sql, function () {
                            layer.open({
                                content: '保存成功',
                                skin: 'msg',
                                time: 2
                            });
                            api.sendEvent({
                                name: 'refreshDraft'
                            });
                        })
                    } else {
                        var sql = "insert into Draft (JSONStr1,JSONStr2,JSONStr3,Remark,CreateTime,UpdateTime,Type,Status) values ('" + jsonstr1 + "','" + jsonstr2 + "','" + jsonstr3 + "','" + Remark + "','" + FLD.getFormatDate() + "',null,-1,null)"
                        DB.executeSql(sql, function () {
                            layer.open({
                                content: '保存成功',
                                skin: 'msg',
                                time: 2
                            });
                            api.sendEvent({
                                name: 'refreshDraft'
                            });
                        })
                    }

                },
                //app提交
                confirmForm() {
                    var that = this;
                    that.ifConfirm = true;
                    if (!that.isUpdate) {
                        that.insertRow();
                    } else {
                        that.saveRow();
                    }
                },

                //---------------------------
                refreshPage(isRefreshChildWindow) {
                    var that = this;
                    setTimeout(function () {
                        //执行正式模块
                        var objName = that.objName;
                        if (objName != '') {
                            tableConfig.initConfig(objName, isRefreshChildWindow);
                        }

                        if (that.keyName != "" && that.keyValue != "") {
                            that.isUpdate = true;
                        }
                        else {
                            that.isUpdate = false;
                        }


                        setTimeout(function () {
                            var approvalSql = "select * from SYS_BillAPFlow a where exists(select * from SYS_BillType b where a.billType = b.billType and b.FListName = '" + api.pageParam.parentObjName + "')";
                            //查询审批记录权限
                            $.post("http://" + FLD.serverIP + "/SQLData/QuerySql", {
                                sql: approvalSql
                            }, function (data) {
                                if (data.data.ds.length > 0) {
                                    that.isApproval = true;
                                    $.post("http://" + FLD.serverIP + "/SQLData/QuerySql", {
                                        sql: "select * from SYS_BillType where FListName='" + api.pageParam.parentObjName + "'"
                                    }, function (billTypeData) {
                                        if (billTypeData.data.ds.length > 0) {
                                            var billType = billTypeData.data.ds[0]["BillType"];
                                            var billCol = billTypeData.data.ds[0]["B_KeyCol"];

                                            that.billquery = " BillType=" + billType + " and BillID=" + that.formData[billCol];

                                        }
                                    }, "json");
                                }
                            }, "json");
                        }, 1000)







                    }, 400);
                },
                //自定义数据导入事件
                selfImportHandler: function (config) {
                    var that = this;
                    that.showMenu = false;
                    if (config.js) {
                        var script = config.js.replace(/\['/g, "vm.formData['");
                        script = script.replace(/\["/g, "vm.formData[\"");
                        script = script.replace(/layer.msg/g, "layerSelfAlert");
                        eval(script);
                    }
                    else {
                        vm.importEvent(config);
                    }
                },
                importEvent: function (config) {
                    var that = this;
                    api.openWin({
                        name: '导入',
                        url: 'formConfigImport.html',
                        reload: true,
                        slidBackEnabled: false,
                        pageParam: {
                            initData: {
                                formDesign: config.reportDesignConfig,
                                sql: config.sql,
                                columns: config.columns,
                                originFormData: vm.formData
                            },
                            objName: that.objName,
                            titleName: config.btnName
                        }
                    })

                },
                //导入数据
                importData: function (columns, selections) {
                    var that = this;
                    var colToColumnList = columns.filter(function (item) { return item.colToColumn != undefined && item.colToColumn != "" });
                    var isMain = false;
                    var mainCount = 0;
                    var childFormDatas = [];
                    for (var z = 0; z < vm.childFormList.length; z++) {
                        childFormDatas.push({
                            name: vm.childFormList[z].title,
                            frameName: vm.childFormList[z].name,
                            record: []
                        });
                    }
                    for (var i = 0; i < selections.length; i++) {
                        for (var j = 0; j < colToColumnList.length; j++) {
                            var toColumnNames = colToColumnList[j].colToColumn.split(',');
                            for (var k = 0; k < toColumnNames.length; k++) {
                                var nameKey = toColumnNames[k].split('.')[0];
                                var nameValue = toColumnNames[k].split('.')[1];
                                //主记录数据
                                if (nameKey == "main" && !isMain) {
                                    mainCount++;
                                    if (vm.formData[nameValue] != undefined) {
                                        vm.formData[nameValue] = selections[i][colToColumnList[j].colName];
                                        vm.execChangeEvent(colToColumnList[j].colName, 1);
                                        vm.execChangeEvent(colToColumnList[j].colName, 2);
                                    }
                                }
                                if (nameKey != "main") {
                                    var recordList = childFormDatas.filter(function (item) { return item.name = nameKey });
                                    if (recordList.length > 0) {
                                        if (recordList[0].record[i] == undefined) {
                                            recordList[0].record[i] = {};
                                        }
                                        recordList[0].record[i][nameValue] = selections[i][colToColumnList[j].colName];
                                    }
                                }
                            }
                        }
                        if (mainCount > 0) {
                            isMain = true;
                        }
                    }
                    //vm.refreshInitActualName();
                    //插入子表数据
                    for (var i = 0; i < childFormDatas.length; i++) {
                        if (childFormDatas[i].record.length > 0) {
                            // window.frames[childFormDatas[i].frameName].window.vm.insertImportData(childFormDatas[i].record);
                            that.$refs['detail' + i][0].insertImportData(childFormDatas[i].record);
                        }
                    }
                },
                //自定义按钮事件
                selfWorkHandler(work) {
                    var script = work.script.replace(/\['/g, "vm.formData['");
                    script = script.replace(/\["/g, "vm.formData[\"");
                    script = script.replace(/layer.msg/g, "layerSelfAlert");
                    vm.showMenu = false;
                    eval(script);
                },
                //按钮显示条件判断
                btn_showCondition(type, btn) {
                    var that = this;
                    try {
                        var _this = this;
                        var result = true;
                        var showScript = "";

                        //普通crud
                        if (type == 1) {
                            if (btn == "新增") {
                                showScript = _this.crudList[0].show;
                            }
                            else if (btn == "编辑") {
                                showScript = _this.crudList[1].show;
                            }
                            else if (btn == "删除") {
                                showScript = _this.crudList[2].show;
                            }
                        }
                        //业务按钮
                        else if (type == 2) {
                            showScript = btn.show;
                        }
                        //调入按钮
                        else if (type == 3) {
                            showScript = btn.btnShow;
                        }
                        if (showScript) {
                            var script = showScript.replace(/\['/g, "_this.formData['");
                            script = script.replace(/\["/g, "_this.formData[\"");
                            script = script.replace(/layer.msg/g, "layerSelfAlert");
                            eval("result=(" + script + ")");
                        }
                        return result;
                    } catch (e) {
                        return true;
                    }
                },
                //显示审核成功
                showApprovalSuccess() {
                    try {
                        if (vm.formData["Approve"]) {
                            return true;
                        }
                        else {
                            return false;
                        }
                    } catch (e) {
                        return false;
                    }
                },
                //显示审核过账图片
                showApprovalImg(type) {
                    //普通审核
                    if (type == 1) {
                        try {
                            if (vm.formData["IsRed"] && vm.formData["IsRed"].toString() == "-1") {
                                return false;
                            }
                            else {
                                return true;
                            }
                        } catch (e) {
                            return true;
                        }
                    }
                    else if (type == 2) {
                        try {
                            if (vm.formData["IsRed"] && vm.formData["IsRed"].toString() == "-1") {
                                return true;
                            }
                            else {
                                return false;
                            }
                        } catch (e) {
                            return false;
                        }
                    }
                },
                //点击上传组件按钮
                btnUploadFile(obj, type) {
                    var that = this;
                    that.currentFileUpload = undefined;
                    var controlno = $(obj).parents(".el-input-group__append").eq(0).parent().children(0).attr("controlno");
                    for (var i = 0; i < that.formDesign.length; i++) {
                        for (var j = 0; j < that.formDesign[i].controls.length; j++) {
                            if (that.formDesign[i].controls[j].baseProperty.controlNo == controlno) {
                                that.currentFileUpload = that.formDesign[i].controls[j];
                            }
                        }
                    }
                    if (that.currentFileUpload) {
                        //上传
                        if (type == 1) {

                        }
                        //下载
                        else if (type == 2) {
                            if (that.formData[that.currentFileUpload.baseProperty.controlName] != undefined && that.formData[that.currentFileUpload.baseProperty.controlName] != "") {
                                var url = "/FileData/DownloadFile?filePath=" + that.formData[that.currentFileUpload.baseProperty.controlName];
                                var html = '<form action="' + url + '" method="post">';
                                html += "</form>";
                                $(html).appendTo('body').submit().remove();
                            }
                        }
                        //删除
                        else if (type == 3) {
                            that.formData[that.currentFileUpload.baseProperty.controlName] = "";
                        }
                    }

                },
                //上传之前控制
                beforeUploadHandler(file) {
                    var that = this;
                    //判断文件大小
                    if (that.currentFileUpload.controlProperty.upload.fileSize != "" && that.currentFileUpload.controlProperty.upload.fileSize != "0") {
                        var maxSize = parseInt(that.currentFileUpload.controlProperty.upload.fileSize);
                        if (file.size > maxSize) {
                            layer.open({
                                content: "请上传小于" + maxSize + "字节长度的文件",
                                skin: 'msg',
                                time: 3
                            });
                            return false;
                        }
                    }
                    //判断文件类型
                    if (that.currentFileUpload.controlProperty.upload.fileType != "") {
                        var fileType = that.currentFileUpload.controlProperty.upload.fileType.toLowerCase();
                        var isMatch = false;
                        for (var i = 0; i < fileType.split(',').length; i++) {
                            if (file.name.toLowerCase().indexOf(fileType.split(',')[i]) >= 0) {
                                isMatch = true;
                            }
                        }
                        if (!isMatch) {
                            layer.open({
                                content: "请上传" + fileType + "类型的文件",
                                skin: 'msg',
                                time: 3
                            });
                            return false;
                        }
                    }
                },

                //新增行
                insertRow() {
                    var that = this;
                    //验证必填项
                    var valitedResult = that.valitedRequired();
                    if (valitedResult.status == 500) {
                        layer.open({
                            content: valitedResult.msg,
                            skin: 'msg',
                            time: 3
                        });
                        that.ifConfirm = false;
                        return;
                    } else {
                        var postData = $.extend(that.formData, {
                            programId: localStorage.getItem("programId"),
                            tableName: that.physicalTableName,
                            createWorkSQL: that.crudList[0].sql,
                            UserID: FLD.getUserInfo().UserID
                        });
                        $.ajax({
                            url: "http://" + FLD.serverIP + "/SQLData/InsertSingleRow",
                            headers: {
                                username: encodeURI(FLD.getUserInfo().UserName)
                            },
                            async: true,
                            data: postData,
                            type: "post",
                            dataType: 'json',
                            success: function (data) {

                                that.ifConfirm = false;
                                if (data.status == 500) {
                                    layer.open({
                                        content: data.msg,
                                        skin: 'msg',
                                        time: 3
                                    });
                                } else {
                                    that.isUpdate = true;

                                    var keyObj = data.data;

                                    that.keyName = keyObj.keyName;
                                    that.keyValue = keyObj.keyValue;

                                    that.formData[that.keyName] = that.keyValue;
                                    var subResult = true;
                                    for (var i = 0; i < that.childFormList.length; i++) {
                                        that.$refs['detail' + i][0].setFixedValuesByTrans(keyObj.keyName, keyObj.keyValue);
                                        //设置查询条件
                                        that.$refs['detail' + i][0].params.filterCondition = that.$refs['detail' + i][0].params.filterCondition.replace(/1='0'/g, that.keyName + "='" + that.keyValue + "'");
                                        var detaailSaveResult = that.$refs['detail' + i][0].saveRow();
                                        if (!detaailSaveResult) {
                                            subResult = false;
                                        }

                                    }
                                    if (subResult) {
                                        //执行完成后的sql业务
                                        if (vm.crudList[0].finishSql) {
                                            let formData = $.extend(vm.formData, {
                                                sql: vm.crudList[0].finishSql
                                            });
                                            $.ajax({
                                                url: "http://" + FLD.serverIP + "/SQLData/QuerySql",
                                                type: "post",
                                                dataType: "json",
                                                async: false,
                                                data: formData,
                                                success: function (data) {
                                                    if (data.status == 200) {

                                                    }
                                                    else {
                                                        layer.open({
                                                            content: data.msg,
                                                            skin: 'msg',
                                                            time: 2
                                                        });
                                                    }
                                                }
                                            });
                                        }

                                        layer.open({
                                            content: "新增成功",
                                            skin: 'msg',
                                            time: 3
                                        });
                                        that.keyName = '';
                                        that.keyValue = 0;
                                        that.draftID = 0;
                                        that.isFirstPage = true;
                                        that.childFormList = [];
                                    }
                                    that.refreshPage(false);

                                }
                            }
                        });


                    }
                },
                //保存行,是否带有成功回调
                saveRow(success_callBack) {
                    var that = this;
                    


                    //验证必填项
                    var valitedResult = that.valitedRequired();
                    if (valitedResult.status == 500) {
                        layer.open({
                            content: valitedResult.msg,
                            skin: 'msg',
                            time: 3
                        });
                        return;
                    }

                    var submitForm = function () {
                        var postData = $.extend(that.formData, {
                            programId: localStorage.getItem("programId"),
                            tableName: that.physicalTableName,
                            keyValue: that.keyValue,
                            updateWorkSQL: that.crudList[1].sql,
                            UserID: FLD.getUserInfo().UserID
                        });
                        var subResult = true;
                        for (var i = 0; i < that.childFormList.length; i++) {
                            subResult = that.$refs['detail' + i][0].saveRow();
                            if (!subResult) {
                                that.ifConfirm = false;
                                break;
                            }
                        }
                        if (subResult) {

                            $.ajax({
                                url: "http://" + FLD.serverIP + "/SQLData/UpdateSingleRow",
                                headers: {
                                    username: encodeURI(FLD.getUserInfo().UserName)
                                },
                                async: true,
                                data: postData,
                                type: "post",
                                dataType: 'json',
                                success: function (data) {
                                    that.ifConfirm = false;
                                    if (data.status == 500) {
                                        layer.open({
                                            content: data.msg,
                                            skin: 'msg',
                                            time: 3
                                        });
                                    } else {
                                        if (success_callBack) {
                                            success_callBack(data);
                                        } else {
                                            if (vm.crudList[0].finishSql) {
                                                let formData = $.extend(vm.formData, {
                                                    sql: vm.crudList[0].finishSql
                                                });
                                                $.ajax({
                                                    url: "http://" + FLD.serverIP + "/SQLData/QuerySql",
                                                    type: "post",
                                                    dataType: "json",
                                                    async: false,
                                                    data: formData,
                                                    success: function (data) {
                                                        if (data.status == 200) {
                                                        }
                                                        else {
                                                            layer.open({
                                                                content: data.msg,
                                                                skin: 'msg',
                                                                time: 2
                                                            });
                                                        }
                                                    }
                                                });
                                            }
                                            layer.open({
                                                content: "更新成功",
                                                skin: 'msg',
                                                time: 3
                                            });
                                            if (that.isNew) {
                                                that.keyName = '';
                                                that.keyValue = 0;
                                                that.draftID = 0;
                                                that.isFirstPage = true;
                                                that.childFormList = [];
                                            }
                                        }
                                        that.refreshPage(false);
                                    }
                                }
                            });

                            
                        }
                    }
                    var checkSQL = that.crudList[1].sql;
                    if (!checkSQL) {
                        submitForm();
                    } else {
                        var postData = $.extend(that.formData, {
                            programId: localStorage.getItem("programId"),
                            tableName: that.physicalTableName,
                            keyValue: that.keyValue,
                            updateWorkSQL: checkSQL,
                            UserID: FLD.getUserInfo().UserID
                        });


                        $.ajax({
                            url: "http://" + FLD.serverIP + "/SQLData/UpdateSingleRowByRollBack",
                            headers: {
                                username: encodeURI(FLD.getUserInfo().UserName)
                            },
                            async: false,
                            data: postData,
                            type: "post",
                            dataType: 'json',
                            success: function (data) {
                                if (data.status == 500) {
                                    layer.open({
                                        content: data.msg,
                                        skin: 'msg',
                                        time: 3
                                    });
                                    that.ifConfirm = false;
                                    return;
                                } else {
                                    submitForm();
                                }
                            }
                        });
                    }
                },

                //select的change事件
                selectChange: function (formObj) {
                    var that = this;
                    if (formObj.controlProperty.select.change != "") {
                        //记录控件原始值和实际值
                        var colOriginName = formObj.baseProperty.controlName;
                        var colOriginValue = that.formData[colOriginName];
                        eval(formObj.controlProperty.select.change.replace(/\[/g, "that.formData[").replace(/layer.msg/g, "layerSelfAlert"));
                    }
                },
                //重新赋值
                refreshInitActualName: function () {
                    var that = this;
                    for (var i = 0; i < that.formDesign.length; i++) {
                        for (var j = 0; j < that.formDesign[i].controls.length; j++) {
                            if (that.formDesign[i].controls[j].baseProperty.controlType == "select") {
                                if (that.formDesign[i].controls[j].controlProperty.select.type == 3) {
                                    var valueList = [];
                                    if (that.formData[that.formDesign[i].controls[j].baseProperty.controlName] != undefined && that.formData[that.formDesign[i].controls[j].baseProperty.controlName] != "") {
                                        valueList.push("'" + that.formData[that.formDesign[i].controls[j].baseProperty.controlName] + "'");
                                    }
                                    var sql = "select * from (" + that.formDesign[i].controls[j].controlProperty.select.dataSource + ")t";
                                    if (valueList.length > 0) {
                                        sql += " where " + that.formDesign[i].controls[j].controlProperty.select.hiddenValue + " in (" + valueList.join(',') + ") ";
                                        $.ajax({
                                            url: "http://" + FLD.serverIP + "/SQLData/GetDataBySql",
                                            async: false,
                                            data: {
                                                programId: localStorage.getItem("programId"),
                                                sql: sql
                                            },
                                            type: "post",
                                            dataType: 'json',
                                            success: function (data) {
                                                if (data.status == 200) {
                                                    that.$set(that.formDesign[i].controls[j].controlProperty.select, "sqlDataSource", data.data.ds);
                                                    that.$set(that.formDesign[i].controls[j].controlProperty.select, "originDataSource", data.data.ds);
                                                    //绑定固定值
                                                    that.$set(that.formDesign[i].controls[j].controlProperty.select, "actualName", "");
                                                    var actualList = data.data.ds.filter(function (item) { return item[that.formDesign[i].controls[j].controlProperty.select.hiddenValue] == that.formData[that.formDesign[i].controls[j].baseProperty.controlName] });
                                                    if (actualList.length > 0) {
                                                        that.$set(that.formDesign[i].controls[j].controlProperty.select, "actualName", actualList[0][that.formDesign[i].controls[j].controlProperty.select.displayValue]);
                                                    }
                                                }
                                            }
                                        });
                                    }
                                    else {
                                        that.$set(that.formDesign[i].controls[j].controlProperty.select, "sqlDataSource", []);
                                        that.$set(that.formDesign[i].controls[j].controlProperty.select, "originDataSource", []);
                                        that.$set(that.formDesign[i].controls[j].controlProperty.select, "actualName", "");
                                    }
                                }
                            }
                        }
                    }
                },
                //验证必填项
                valitedRequired() {
                    var that = this;
                    var resultObj = { status: 200, msg: "" };
                    for (var i = 0; i < that.formDesign.length; i++) {
                        for (var j = 0; j < that.formDesign[i].controls.length; j++) {
                            if (that.formDesign[i].controls[j].baseProperty.isRequired) {
                                if (that.formData[that.formDesign[i].controls[j].baseProperty.controlName] === "" || that.formData[that.formDesign[i].controls[j].baseProperty.controlName] === null) {
                                    resultObj = {
                                        status: 500,
                                        msg: that.formDesign[i].controls[j].baseProperty.labelName + "字段不能为空!"
                                    };
                                }
                            }
                        }
                    }
                    return resultObj;
                },

                //传递参数，默认值
                transParamsDefault() {
                    var that = this;

                    for (var i = 0; i < that.childFormList.length; i++) {
                        var defaultParams = that.childFormList[i].defaultParams.split(',');
                        var defaultChildParams = that.childFormList[i].defaultChildParams.split(',');
                        for (var j = 0; j < defaultParams.length; j++) {
                            that.$refs['detail' + i][0].setFixedValues(defaultChildParams[j], that.formData[defaultParams[j]]);
                        }
                        var transParams = that.childFormList[i].transParams.split(',');
                        var transChildParams = that.childFormList[i].transChildParams.split(',');
                        for (var j = 0; j < transParams.length; j++) {
                            that.$refs['detail' + i][0].setFixedValuesByTrans(transChildParams[j], that.formData[transParams[j]]);
                        }
                    }
                },

                //select数据变化的回调函数
                selectDataChange: function (formCol) {
                    var that = this;
                    that.selectChange(formCol);
                    that.dataChange(formCol);
                },
                //数据变化的回调函数
                dataChange: function (formCol) {
                    var that = this;
                    if (formCol.baseProperty.controlCallBack) {
                        var script = formCol.baseProperty.controlCallBack.replace(/\['/g, "that.formData['");
                        script = script.replace(/\["/g, "that.formData[\"");
                        script = script.replace(/layer.msg/g, "layerSelfAlert");
                        eval(script);
                        that.refreshInitActualName();
                    }
                    if (formCol.baseProperty.controlChange) {
                        var script = formCol.baseProperty.controlChange.replace(/\['/g, "that.formData['");
                        script = script.replace(/\["/g, "that.formData[\"");
                        script = script.replace(/layer.msg/g, "layerSelfAlert");
                        eval(script);
                        that.refreshInitActualName();
                    }
                },
                /*系统函数开始*/
                //ajax查询
                post(sql, param, callBack) {
                    var that = this;
                    param["P_UserID"] = FLD.getUserInfo().UserID;
                    param["UserID"] = FLD.getUserInfo().UserID;
                    param["sql"] = sql;
                    param["programId"] = localStorage.getItem("programId");
                    $.ajax({
                        url: "http://" + FLD.serverIP + "/SQLData/QuerySql",
                        type: "post",
                        dataType: "json",
                        async: false,
                        data: param,
                        success: function (data) {
                            if (data.status == 200) {
                                callBack(data.data);
                            }
                            else {
                                alert(data.msg)
                            }
                        }
                    });
                },
                //获取列下拉数据源对象
                queryColumnObj(rowDataSource, colName, condition, objValue) {
                    var that = this;

                    var currentCol = [];
                    for (var i = 0; i < that.formDesign.length; i++) {
                        for (var j = 0; j < that.formDesign[i].controls.length; j++) {
                            if (that.formDesign[i].controls[j].baseProperty["controlName"] == colName) {
                                currentCol.push(that.formDesign[i].controls[j]);
                            }
                        }
                    }
                    var returnArray = [];
                    if (currentCol.length > 0) {
                        currentCol = currentCol[0];
                        try {
                            returnArray = eval("currentCol.controlProperty.select.sqlDataSource.filter(function(item){return item." + condition + ";})")
                        } catch (e) {
                            returnArray = [];
                        }
                    }
                    var returnValue = "";
                    if (returnArray.length > 0) {
                        returnValue = returnArray[0][objValue];
                    }
                    return returnValue;
                },
                //手动调用change或回调事件
                execChangeEvent(formCol, eventType) {
                    var that = this;
                    for (var i = 0; i < that.formDesign.length; i++) {
                        var currentCol = that.formDesign[i].controls.filter(function (item) { return item.baseProperty.controlName == formCol });
                        if (currentCol.length > 0) {
                            currentCol = currentCol[0];
                            if (eventType == 1) {
                                that.dataChange(currentCol);
                            }
                            else if (eventType == 2) {
                                that.selectChange(currentCol);
                            }

                        }
                    }
                },
                //系统默认常量时间
                getSYDefaultValue(funcName) {
                    var that = this;
                    if (funcName == "getdate()") {
                        return FLD.getFormatDate();
                    } else if (funcName.indexOf('@') > -1) {
                        return userInfo[funcName.replace(/@/g, '')];
                    } else {
                        return funcName;
                    }

                },
                //是否为禁用业务流权限
                isUnWorkRoleList(workName) {
                    var that = this;
                    var isUse = true;
                    try {
                        //如果功能权限在这个数组中，则禁用
                        if (that.unWorkRoleList.filter(function (item) { return item.FunName == workName }).length > 0) {
                            isUse = false;
                        }
                        //JSLINQ注释掉的
                        // if (JSLINQ(that.unWorkRoleList).where(function (item) { return item.FunName == workName }).ToArray().length > 0) {
                        //     isUse = false;
                        // }
                    } catch (e) {
                    }
                    return isUse;
                },

                //设置审核弹窗
                setApprovalWindow(title, approvalTitle, callBack) {
                    var that = this;
                    that.approvalTitle = approvalTitle;
                    approvalCallBack = callBack;
                    that.showApproval = true;
                },
                approvalConfirm(index) {
                    var that = this;
                    that.showApproval = false;
                    approvalCallBack(that.approvalReason || '', index);
                },

                /*系统函数结束*/
                /*change获取数据机制处理
                  用于change过程中反复调用后台处理的机制问题
                */
                changeDataAjax: function (datasource, query) {
                    var that = this;
                    var dsResult = that.changeDataSource.filter(function (item) { return item.datasource == datasource && item.query == query; })
                    //JSLINQ注释掉的
                    // var dsResult = JSLINQ(that.changeDataSource).where(function (item) { return item.datasource == datasource && item.query == query; }).ToArray();
                    if (dsResult.length == 0) {
                        var returnData = [];
                        var sql = "select * from (" + datasource + ")t";
                        sql += " where " + query;
                        $.ajax({
                            url: "http://" + FLD.serverIP + "/SQLData/GetDataBySql",
                            async: false,
                            data: {
                                programId: localStorage.getItem("programId"),
                                sql: sql
                            },
                            type: "post",
                            dataType: 'json',
                            success: function (data) {
                                if (data.status == 200) {
                                    returnData = data.data.ds;
                                    that.changeDataSource.push({
                                        datasource: datasource,
                                        query: query,
                                        data: returnData
                                    });
                                }
                            }
                        });
                        return returnData;
                    }
                    else {
                        return dsResult[0].data;
                    }
                },
                onClickLeft() {
                    var that = this;
                    this.$dialog.confirm({
                        title: '提示',
                        message: '是否退出' + that.titleName + '界面?'
                    }).then(() => {
                        api.closeWin();
                    }).catch(() => {

                    });

                }
            }
        });


        var tableConfig = {
            //设置配置
            set: function (options, isRefreshChildWindow) {
                if (options.childFormList == null) {
                    options.childFormList = [];
                }
                if (vm.childFormList.length == 0) {
                    vm.childFormList = options.childFormList;
                }
                var rowDesignFormData = [];
                if (!options.formDesign) {
                    options.formDesign = [];
                }
                var animateHeightIndex = 0;
                for (var i = 0; i < options.formDesign.length; i++) {
                    var rowId = options.formDesign[i].baseProperty.rowId;



                    if (options.formDesign[i].baseProperty.isFold && options.formDesign[i].baseProperty.controlType != 'hidden') {
                        animateHeightIndex++;
                    }
                    if (options.formDesign[i].baseProperty.controlType == "select") {
                        //下拉框数据加载
                        if (options.formDesign[i].controlProperty.select.type < 3) {
                            var sql = options.formDesign[i].controlProperty.select.dataSource;
                            $.ajax({
                                url: "http://" + FLD.serverIP + "/SQLData/GetDataBySql",
                                async: false,
                                data: {
                                    programId: localStorage.getItem("programId"),
                                    sql: sql
                                },
                                type: "post",
                                dataType: 'json',
                                success: function (data) {
                                    if (data.status == 200) {
                                        options.formDesign[i].controlProperty.select.actualName = [];

                                        vm.$set(options.formDesign[i].controlProperty.select, "sqlDataSource", data.data.ds);
                                        vm.$set(options.formDesign[i].controlProperty.select, "originDataSource", data.data.ds);

                                        //判断隐藏值类型和当前赋值类型是否一致
                                        if (data.data.ds.length > 0 && vm.formData[options.formDesign[i].baseProperty.controlName]) {
                                            var dataType = typeof (data.data.ds[0][options.formDesign[i].controlProperty.select.hiddenValue]);
                                            if (dataType != typeof (vm.formData[options.formDesign[i].baseProperty.controlName])) {
                                                if (dataType == "int") {
                                                    vm.formData[options.formDesign[i].baseProperty.controlName] = parseInt(vm.formData[options.formDesign[i].baseProperty.controlName]);
                                                }
                                                else if (dataType == "boolean") {

                                                    vm.formData[options.formDesign[i].baseProperty.controlName] = Boolean(parseInt(vm.formData[options.formDesign[i].baseProperty.controlName]));
                                                }
                                            }
                                            else {
                                                vm.formData[options.formDesign[i].baseProperty.controlName] = vm.formData[options.formDesign[i].baseProperty.controlName];
                                            }

                                            if (dataType != typeof (options.formDesign[i].baseProperty.defaultValue)) {
                                                if (dataType == "int") {
                                                    options.formDesign[i].baseProperty.defaultValue = parseInt(options.formDesign[i].baseProperty.defaultValue);
                                                }
                                                else if (dataType == "boolean") {
                                                    options.formDesign[i].baseProperty.defaultValue = Boolean(parseInt(options.formDesign[i].baseProperty.defaultValue));
                                                }
                                            }
                                            for (var j in data.data.ds) {
                                                if (options.formDesign[i].baseProperty.defaultValue == data.data.ds[j][options.formDesign[i].controlProperty.select.hiddenValue]) {
                                                    options.formDesign[i].controlProperty.select.actualName = data.data.ds[j][options.formDesign[i].controlProperty.select.displayValue].join();
                                                }
                                            }

                                        }
                                    }
                                }
                            });
                        } else if (options.formDesign[i].controlProperty.select.type == 3) {
                            if (options.formDesign[i].controlProperty.select.chooseType == 1) {
                                var valueList = [];
                                if (vm.formData[options.formDesign[i].baseProperty.controlName] != undefined && vm.formData[options.formDesign[i].baseProperty.controlName] != "") {
                                    valueList.push("'" + vm.formData[options.formDesign[i].baseProperty.controlName] + "'");
                                }
                                var sql = "select * from (" + options.formDesign[i].controlProperty.select.dataSource + ")t";
                                if (valueList.length > 0) {
                                    sql += " where " + options.formDesign[i].controlProperty.select.hiddenValue + " in (" + valueList.join(',') + ") ";
                                    $.ajax({
                                        url: "http://" + FLD.serverIP + "/SQLData/GetDataBySql",
                                        async: false,
                                        data: {
                                            programId: localStorage.getItem("programId"),
                                            sql: sql
                                        },
                                        type: "post",
                                        dataType: 'json',
                                        success: function (data) {
                                            if (data.status == 200) {
                                                vm.$set(options.formDesign[i].controlProperty.select, "sqlDataSource", data.data.ds);
                                                vm.$set(options.formDesign[i].controlProperty.select, "originDataSource", data.data.ds);

                                                //绑定固定值
                                                vm.$set(options.formDesign[i].controlProperty.select, "actualName", "");
                                                var actualList = data.data.ds.filter(function (item) { return item[options.formDesign[i].controlProperty.select.hiddenValue] == vm.formData[options.formDesign[i].baseProperty.controlName] });
                                                if (actualList.length > 0) {
                                                    vm.$set(options.formDesign[i].controlProperty.select, "actualName", actualList[0][options.formDesign[i].controlProperty.select.displayValue]);
                                                }
                                            }
                                        }
                                    });
                                }
                                else {
                                    vm.$set(options.formDesign[i].controlProperty.select, "sqlDataSource", []);
                                    vm.$set(options.formDesign[i].controlProperty.select, "originDataSource", []);
                                    vm.$set(options.formDesign[i].controlProperty.select, "actualName", "");

                                }
                            }
                            else {
                                var valueList = "";
                                if (vm.formData[options.formDesign[i].baseProperty.controlName] != undefined && vm.formData[options.formDesign[i].baseProperty.controlName] != "") {
                                    valueList = vm.formData[options.formDesign[i].baseProperty.controlName];
                                }
                                var sql = "select * from (" + options.formDesign[i].controlProperty.select.dataSource + ")t";
                                if (valueList) {
                                    sql += " where " + options.formDesign[i].controlProperty.select.hiddenValue + " in (" + valueList + ") ";


                                    $.ajax({
                                        url: "http://" + FLD.serverIP + "/SQLData/GetDataBySql",
                                        async: false,
                                        data: {
                                            programId: localStorage.getItem("programId"),
                                            sql: sql
                                        },
                                        type: "post",
                                        dataType: 'json',
                                        success: function (data) {
                                            if (data.status == 200) {
                                                vm.$set(options.formDesign[i].controlProperty.select, "sqlDataSource", data.data.ds);
                                                vm.$set(options.formDesign[i].controlProperty.select, "originDataSource", data.data.ds);
                                                //绑定固定值
                                                vm.$set(options.formDesign[i].controlProperty.select, "actualName", "");
                                                var displayValues = data.data.ds.filter(function (item) { return item[options.formDesign[i].controlProperty.select.displayValue] });
                                                var values = [];
                                                for (var z in displayValues) {
                                                    values.push(displayValues[z][options.formDesign[i].controlProperty.select.displayValue])
                                                }
                                                vm.$set(options.formDesign[i].controlProperty.select, "actualName", values.join());
                                            }
                                        }
                                    });
                                }
                                else {
                                    vm.$set(options.formDesign[i].controlProperty.select, "actualName", "");
                                    vm.$set(options.formDesign[i].controlProperty.select, "sqlDataSource", []);
                                    vm.$set(options.formDesign[i].controlProperty.select, "originDataSource", []);
                                }
                            }

                        }
                    }

                    var designDataList = rowDesignFormData.filter(function (item) { return item.rowId == rowId; })
                    if (designDataList.length > 0) {
                        designDataList[0].controls.push(options.formDesign[i]);
                    }
                    else {
                        rowDesignFormData.push({
                            rowId: rowId,
                            controls: [options.formDesign[i]]
                        });
                    }
                }
                vm.animateHeight = animateHeightIndex * 44;
                vm.formDesign = rowDesignFormData;
                vm.physicalTableName = options.physicalTableName;
                vm.workList = options.workList;
                for(var i in vm.workList){
                    if(vm.workList[i].name == '流程审批'){
                        vm.approvalData = vm.workList[i];
                    }
                }
                vm.crudList = options.crudList;
                if (options.importConfig) {
                    var topImportConfig = [];
                    var detailImportConfig = [];
                    for (var i in options.importConfig) {
                        if (options.importConfig[i].btnPosition == '1') {
                            detailImportConfig.push(options.importConfig[i])
                        } else {
                            topImportConfig.push(options.importConfig[i])
                        }
                    }
                    vm.topImportConfig = topImportConfig;
                    vm.detailImportConfig = detailImportConfig;
                }
                vm.$nextTick(function () {
                    for (var i in vm.childFormList) {
                        vm.$refs['detail' + i][0].detailImportConfig = vm.detailImportConfig;
                    }
                })



                for (var i in vm.formDesign) {
                    for (var j in vm.formDesign[i].controls) {
                        if (vm.formDesign[i].controls[j].baseProperty.defaultValue && vm.formDesign[i].controls[j].baseProperty.defaultValue.indexOf('@') > -1) {
                            vm.selectChange(vm.formDesign[i].controls[j])
                        }
                    }
                }


            },
            //初始化配置
            initConfig: function (objName, isRefreshChildWindow) {
                $.post("http://" + FLD.serverIP + "/AppFormDetail/GetDataByName", {
                    programId: localStorage.getItem("programId"),
                    objName: objName
                }, function (data) {
                    console.log(data.data.ds[0].formDesignConfig)
                    data = data.data;
                    $.globalData = data;
                    //判断主键字段是否存在
                    vm.physicalTableName = data.ds[0].physicalTableName;
                    if (vm.keyName != "" && vm.keyValue != "") {
                        $.post("http://" + FLD.serverIP + "/SQLData/GetTableByKeyId", {
                            programId: localStorage.getItem("programId"),
                            physicalTableName: data.ds[0].physicalTableName,
                            keyName: vm.keyName,
                            keyValue: vm.keyValue
                        }, function (data) {


                            if (data.status == 500) {
                                layer.open({
                                    content: data.msg,
                                    skin: 'msg',
                                    time: 3
                                });
                            } else {
                                if (data.data.ds.length > 0) {
                                    var result = data.data.ds[0];

                                    vm.formData = result;

                                    tableConfig.set({
                                        childFormList: JSON.parse($.globalData.ds[0].childFormsConfig),
                                        formDesign: JSON.parse($.globalData.ds[0].formDesignConfig),
                                        physicalTableName: $.globalData.ds[0].physicalTableName,
                                        workList: JSON.parse($.globalData.ds[0].worksConfig),
                                        crudList: JSON.parse($.globalData.ds[0].crudConfig),
                                        importConfig: JSON.parse($.globalData.ds[0].importConfig)
                                    }, isRefreshChildWindow);
                                }
                            }
                            setTimeout(function () {
                                vm.transParamsDefault();
                                var childFormList = JSON.parse($.globalData.ds[0].childFormsConfig)
                                for (var i in childFormList) {
                                    vm.$refs['detail' + i][0].setFixedValues(vm.keyName, vm.keyValue);
                                }


                                vm.isFirstPage = false;
                            }, 200);
                        }, "json");
                    } else {
                        //设置默认值
                        if (data.ds[0].formDesignConfig) {
                            var newFormData = {};
                            var designControls = JSON.parse(data.ds[0].formDesignConfig);
                            for (var i = 0; i < designControls.length; i++) {
                                if (designControls[i].baseProperty.defaultValue && designControls[i].baseProperty.controlType != 'fileUpload') {
                                    newFormData[designControls[i].baseProperty.controlName] = vm.getSYDefaultValue(designControls[i].baseProperty.defaultValue);
                                }
                                else {
                                    newFormData[designControls[i].baseProperty.controlName] = "";
                                }
                            }
                            if (api.pageParam.defaultValue) {

                                newFormData = Object.assign(newFormData, api.pageParam.defaultValue);
                            }
                            if (vm.draftID) {
                                var sql = "select * from Draft where DraftID='" + vm.draftID + "'";
                                var dbValue = DB.selectSqlSync(sql)[0];
                                vm.formData = JSON.parse(dbValue.JSONStr1);
                            } else {
                                vm.formData = newFormData;
                            }

                        }


                        tableConfig.set({
                            childFormList: JSON.parse(data.ds[0].childFormsConfig),
                            formDesign: JSON.parse(data.ds[0].formDesignConfig),
                            physicalTableName: data.ds[0].physicalTableName,
                            workList: JSON.parse(data.ds[0].worksConfig),
                            crudList: JSON.parse(data.ds[0].crudConfig),
                            importConfig: JSON.parse(data.ds[0].importConfig)
                        }, isRefreshChildWindow);
                        setTimeout(function () {
                            vm.transParamsDefault();
                            vm.isFirstPage = false;
                        }, 200);
                    }
                }, "json");
            }
        }

    };



</script>

</html>